package com.ts.api.module.product.service.impl;

import com.ts.api.module.product.entity.po.ProductPlanPO;
import com.ts.api.module.product.entity.qo.ProductPlanLimitQO;
import com.ts.api.module.product.service.ProductPlanLimitService;
import com.ts.api.module.product.service.ProductUserMatchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ProductPlanLimitServiceImpl implements ProductPlanLimitService {

    @Autowired
    private ProductUserMatchService productUserMatchService;

    @Override
    public boolean hasPlanLimitTotalExceed(ProductPlanPO productPlanPO) {
        Long id = productPlanPO.getId();
        ProductPlanLimitQO productPlanLimitQO = ProductPlanLimitQO.createByNowTime(id);
        Integer nowApplyTotal = productUserMatchService.countPlanApplyTotal(productPlanLimitQO);
        Integer maxLimit = productPlanPO.getMaxLimit();

        //  超出限量
        if (maxLimit != 0 && nowApplyTotal >= maxLimit) {
            return true;
        }
        return false;
    }

    @Override
    public void createPreAllocatePlanUserCount() {

    }
}
